#include <cstdio>
#include <cstring>

#define MAXH 40+5
#define MAXW 10+5

int H, W;
bool G[MAXH][MAXW];
bool book[MAXH][MAXW];
int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &H, &W);
		getchar();
		memset(G, 0, sizeof(G));
		for (int i=1; i<=H; i++) {
			for (int j=1; j<=W; j++) {
				char c;
				scanf("%c", &c);
				if (c=='*') G[i][j]=true;
			}
			getchar();
		}
//		for (int i=1; i<=H; i++) {
//			for (int j=1; j<=W; j++) {
//				printf("%c", G[i][j]?'*':'o');
//			}
//			printf("\n");
//		}
		memset(book, 0, sizeof(book));
		int cnt = 0;
		for (int i=1; i<=H; i++) {
			for (int j=1; j<=W; j++) {
				if (!G[i][j] || book[i][j]) continue;
				book[i][j] = true;
				//printf("%d %d\n", i, j);
				cnt++;
				for (int k=0; k<4; k++) {
					int ti = i+dir[k][0];
					int tj = j+dir[k][1];
					if (ti<1 || ti>H || tj<1 || tj>W) continue;
					if (G[ti][tj] && !book[ti][tj]) {
						book[ti][tj] = true;
						break;
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}
